Variantenschnellzugriff
Layout-Varianten lassen sich im ALV-Grid komfortabel verwalten. Manchmal wäre es jedoch schön, wenn man einen schnelleren Zugriff auf die einzelnen Varianten hätte. Mit diesem Programm zeige ich die, wie das einfach möglich ist.
Vorbereitungen
- Dynpro 100 muss angelegt und mit einem Customcontainer bestückt werden (Name: CONTAINER).
- Status 100 anlegen; F3, SHIFT-F3 und F12 mit Funktionscode BACK belegen.
Vorgehen
Wenn du das Programm gestartet hast, definierst du dir zwei oder drei Varianten. du wirst sehen, dass diese Varianten dann in der Toolbar auftauchen. So kann wirklich schnell und komfortabel zwischen verschiedenen Sichten hin- und hergewechselt werden.
Coding
*&---------------------------------------------------------------------* *& Report ZZ_GRID_VARIANT *&---------------------------------------------------------------------* REPORT zz_grid_variant. *** Class for event receiver CLASS lcl_event_receiver DEFINITION DEFERRED. *** global data DATA gr_grid TYPE REF TO cl_gui_alv_grid. DATA gr_cont TYPE REF TO cl_gui_custom_container. DATA gr_evth TYPE REF TO lcl_event_receiver. DATA gt_vbak TYPE STANDARD TABLE OF vbak. DATA gs_variant TYPE disvariant. *----------------------------------------------------------------------* * CLASS lcl_event_receiver DEFINITION *----------------------------------------------------------------------* CLASS lcl_event_receiver DEFINITION. PUBLIC SECTION. CLASS-METHODS: *** event for adding buttons to toolbar handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid IMPORTING e_object e_interactive sender, *** event for pressed buttons handle_user_command FOR EVENT user_command OF cl_gui_alv_grid IMPORTING e_ucomm sender. ENDCLASS. "lcl_event_receiver DEFINITION *----------------------------------------------------------------------* * CLASS lcl_event_receiver IMPLEMENTATION *----------------------------------------------------------------------* CLASS lcl_event_receiver IMPLEMENTATION. METHOD handle_toolbar. DATA ls_toolbar TYPE stb_button. DATA ls_variant TYPE disvariant. *** Variants DATA lt_ltdx TYPE STANDARD TABLE OF ltdx. FIELD-SYMBOLS <ltdx> TYPE ltdx. *** Variant texts DATA lt_ltdxt TYPE STANDARD TABLE OF ltdxt. FIELD-SYMBOLS <ltdxt> TYPE ltdxt. *** Set buttons for variants SELECT * FROM ltdx INTO TABLE lt_ltdx UP TO 10 ROWS WHERE relid = 'LT' AND report = gs_variant-report AND handle = gs_variant-handle AND srtf2 = 0 AND ( username = space OR username = sy-uname ) ORDER BY username variant. IF sy-subrc = 0. *** add Seperator to toolbar ls_toolbar-function = 'DUMMY'. ls_toolbar-butn_type = '3'. "TYPE TB_BTYPE => Domain values! APPEND ls_toolbar TO e_object->mt_toolbar. *** Get variant texts SELECT * FROM ltdxt INTO TABLE lt_ltdxt FOR ALL ENTRIES IN lt_ltdx WHERE relid = 'LT' AND report = gs_variant-report AND handle = gs_variant-handle AND variant = lt_ltdx-variant AND langu = sy-langu. *** Get actual variant CALL METHOD sender->get_variant IMPORTING es_variant = ls_variant. LOOP AT lt_ltdx ASSIGNING <ltdx>. *** get variant text READ TABLE lt_ltdxt ASSIGNING <ltdxt> WITH KEY variant = <ltdx>-variant. *** Button to create customer order with template CLEAR ls_toolbar. ls_toolbar-function = '$'. ls_toolbar-function+1 = <ltdx>-variant. IF <ltdx>-variant(1) = '/'. *** global variant ls_toolbar-icon = icon_alv_variant_choose. ELSE. *** user specific variant ls_toolbar-icon = icon_usergroup. ENDIF. ls_toolbar-butn_type = '0'. ls_toolbar-disabled = space. IF <ltdxt> IS ASSIGNED. ls_toolbar-text = <ltdxt>-text. ELSE. ls_toolbar-text = <ltdx>-variant. ENDIF. ls_toolbar-quickinfo = space. IF ls_variant-variant = <ltdx>-variant. ls_toolbar-checked = 'X'. ELSE. ls_toolbar-checked = space. ENDIF. APPEND ls_toolbar TO e_object->mt_toolbar. ENDLOOP. ENDIF. "Variants exist? ENDMETHOD. "handle_toolbar METHOD handle_user_command. *** data DATA lv_user_specific TYPE c. DATA ls_variant TYPE disvariant. DATA ls_stable TYPE lvc_s_stbl. DATA lt_fieldcat TYPE lvc_t_fcat. DATA lt_sort TYPE lvc_t_sort. DATA lt_filter TYPE lvc_t_filt. DATA ls_layout TYPE lvc_s_layo. *** Variant CLEAR ls_variant. ls_variant-variant = e_ucomm. SHIFT ls_variant-variant LEFT BY 1 PLACES. ls_variant-report = gs_variant-report. ls_variant-handle = gs_variant-handle. IF ls_variant-variant(1) <> '/'. ls_variant-username = sy-uname. lv_user_specific = 'X'. ENDIF. CALL METHOD sender->get_frontend_fieldcatalog IMPORTING et_fieldcatalog = lt_fieldcat. CALL FUNCTION 'LVC_VARIANT_SELECT' EXPORTING i_dialog = space i_user_specific = lv_user_specific it_default_fieldcat = lt_fieldcat IMPORTING et_fieldcat = lt_fieldcat et_sort = lt_sort et_filter = lt_filter CHANGING cs_variant = ls_variant EXCEPTIONS OTHERS = 6. IF sy-subrc = 0. *** set all neccessary objects of chosen variant CALL METHOD sender->set_variant( ls_variant ). CALL METHOD sender->set_frontend_fieldcatalog( lt_fieldcat ). CALL METHOD sender->set_filter_criteria( lt_filter ). CALL METHOD sender->set_sort_criteria( lt_sort ). ls_stable = 'XX'. CALL METHOD sender->refresh_table_display EXPORTING is_stable = ls_stable i_soft_refresh = space. ENDIF. ENDMETHOD. "handle_user_command ENDCLASS. "lcl_event_receiver IMPLEMENTATION *** _______________________________________________________ *** *** *** *** START OF PROGRAM *** _______________________________________________________ *** *** *** START-OF-SELECTION. SELECT * FROM vbak INTO TABLE gt_vbak UP TO 30 ROWS. CALL SCREEN 100. *&---------------------------------------------------------------------* *& Module PBO OUTPUT *&---------------------------------------------------------------------* MODULE pbo OUTPUT. SET PF-STATUS '100'. SET TITLEBAR '100'. CLEAR sy-ucomm. PERFORM init_grid. ENDMODULE. " PBO OUTPUT *&---------------------------------------------------------------------* *& Module PAI INPUT *&---------------------------------------------------------------------* MODULE pai INPUT. CASE sy-ucomm. WHEN 'BACK'. SET SCREEN 0. LEAVE SCREEN. ENDCASE. ENDMODULE. " PAI INPUT *&---------------------------------------------------------------------* *& Form init_grid *&---------------------------------------------------------------------* FORM init_grid. IF gr_grid IS INITIAL. *** create custom container CREATE OBJECT gr_cont EXPORTING container_name = 'CONTAINER'. *** Create ALV Grid CREATE OBJECT gr_grid EXPORTING i_parent = gr_cont. *** Set variant CLEAR gs_variant. gs_variant-report = sy-repid. gs_variant-handle = 'GRID'. gs_variant-username = sy-uname. *** Set display CALL METHOD gr_grid->set_table_for_first_display EXPORTING i_structure_name = 'VBAK' is_variant = gs_variant i_save = 'A' i_default = 'X' CHANGING it_outtab = gt_vbak EXCEPTIONS OTHERS = 4. *** Create event handler for grid CREATE OBJECT gr_evth. SET HANDLER gr_evth->handle_user_command gr_evth->handle_toolbar FOR gr_grid. *** set toolbar interactive gr_grid->set_toolbar_interactive( ). ENDIF. ENDFORM. "init_grid
Button types
0 Button (normal)
1 Menü + Defaultbutton
2 Menü
3 Separator
4 Radiobutton
5 Auswahlknopf (Checkbox)
6 Menüeintrag
Letzte Artikel von Enno Wulff (Alle anzeigen)
- 7. December: Excel Racing Simulation – Root Vole Race - 7. Dezember 2024
- 5. December: ABAPConf - 5. Dezember 2024
- 4. December: Only a lazy developer is a good developer - 4. Dezember 2024